var preorderTraversal = function (root) {
  let res = [];
  function pushRoot (node) {
    if (node !== null) {
      res.push(node.val);
      if (node.left !== null) {
        pushRoot(node.left);
      }
      if (node.right !== null) {
        pushRoot(node.right);
      }
    }
  }
  pushRoot(root);
  return res;
}